<?php
//****************************************************
// JTBC CMS Power by Jetiben.com
// Email: jetiben@hotmail.com
// Web: http://www.jtbc.net.cn/
//****************************************************
function get_sorts() {
	global $db, $sort_database, $ngenre;
	
	$db->sqlcmd = "select * from $sort_database where sort_genre='$ngenre' order by sort_order";
	return $db->execute_reader ();
}
function jtbc_cms_module_list() {
	global $db,$ngenre,$nlisttopx ,$ndatabase, $nidfield,$sort_idfield;
	
	$classid = ii_get_num ( $_GET ['classid'] );
	$toffset = ii_get_num ( $_GET ['offset'] );
	
	$sorts = get_sorts ();
	
	$sql = "select * from $ndatabase where " . ii_cfname ( 'hidden' ) . "=0";
	if (! empty ( $classid )) {
		$sql .= " and " . ii_cfname ( 'class' ) . "=$classid";
		foreach ($sorts as $row){
			if($row[$sort_idfield]==$classid){
				$sort = $row;
				break;
			}
		}
	}
	$sql .= " order by " . ii_cfname ( 'time' ) . " desc";
	$tcp = new cc_cutepage ();
	$tcp->sqlstr = $sql;
	$tcp->offset = $toffset;
	$tcp->init ();
	$list = $tcp->get_rs_array ();
	$pagestr = $tcp->get_web_pagestr ();
	include View ( "list" );
}

function jtbc_cms_module_detail() {
	global $db, $ndatabase, $nidfield;
	
	$id = ii_get_num ( $_GET ['id'] );
	
	$sorts = get_sorts ();
	
	$sql = "select * from $ndatabase where " . ii_cfname ( 'hidden' ) . "=0 and $nidfield=$id";
	$db->sqlcmd = $sql;
	$result = $db->get_first ();
	include View ( "detail" );
}

function jtbc_cms_module_index() {
	global $db, $ndatabase, $sort_idfield;
	
	$sorts = get_sorts ();
	
	$result = array ();
	foreach ( $sorts as $sort ) {
		$sql = "select * from $ndatabase where " . ii_cfname ( 'class' ) . "='" . $sort [$sort_idfield] . "'";
		$db->sqlcmd = $sql;
		$data = $db->execute_reader ();
		$result [] = array ("sort" => $sort, "data" => $data );
	}
	
	include View ( "index" );
}

function jtbc_cms_module_ajax_list(){
	global $db ,$ndatabase;
	
	$classid = ii_get_num ( $_GET ['classid'] );
	
	$sql = "select * from $ndatabase where " . ii_cfname ( 'hidden' ) . "=0 ";	
	if (! empty ( $classid )) {
		$sql .= " and " . ii_cfname ( 'class' ) . "=$classid";
	}
	$sql .= " order by " . ii_cfname ( 'time' ) . " desc limit 8";
	
	$db->sqlcmd = $sql;
	$articleList = $db->execute_reader ();
	include View ( "ajax_list" );
}

function jtbc_cms_module() {
	switch ($_GET ['type']) {
		case 'list' :
			return jtbc_cms_module_list ();
			break;
		case 'detail' :
			return jtbc_cms_module_detail ();
			break;
		case 'index' :
			return jtbc_cms_module_index ();
			break;
		case 'ajax_list' :
			return jtbc_cms_module_ajax_list ();
			break;
		default :
			return jtbc_cms_module_index ();
			break;
	}
}
//****************************************************
// JTBC CMS Power by Jetiben.com
// Email: jetiben@hotmail.com
// Web: http://www.jtbc.net.cn/
//****************************************************
?>
